package com.lottery.ruok.lottrey.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.retrofitModule.response.GetWinningResponse;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by ASUS on 2017/9/17.
 */

public class WinningAdapter extends BaseAdapter {
    ArrayList<GetWinningResponse> getWinningResponses;
    private Context context;

    public WinningAdapter(ArrayList<GetWinningResponse> getWinningResponses, Context context) {
        this.getWinningResponses = getWinningResponses;
        this.context = context;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view != null) {
            holder = (ViewHolder) view.getTag();
        } else {
            view = LayoutInflater.from(context).inflate(R.layout.rank_item1, viewGroup, false);
            holder = new ViewHolder(view);
            view.setTag(holder);
        }

        if(getWinningResponses != null && getWinningResponses.size() != 0){
            holder.name.setText(getWinningResponses.get(i % getWinningResponses.size()).getUsername());
            holder.result.setText(getWinningResponses.get(i % getWinningResponses.size()).getProfit());
            holder.type.setText(getWinningResponses.get(i % getWinningResponses.size()).getName());
        }

        return view;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    static class ViewHolder {
        @BindView(R.id.name)
        TextView name;
        @BindView(R.id.result)
        TextView result;
        @BindView(R.id.type)
        TextView type;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
